package com.nut.spp.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nut.spp.entity.MemberCoupon;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface MemberCouponMapper extends BaseMapper<MemberCoupon> {

//    @Select("select id,money,type,status,end_time from biz_member_coupon where member_id=#{memberId} and type={type} and status=0 and deleted=0")
//    List<MemberCoupon> list(@Param("memberId") Long memberId);

    IPage<MemberCoupon> listPage(Page page,
                                 @Param("memberId") Long memberId,
                                 @Param("type") Integer type,
                                 @Param("status") Integer status);

    @Select("select count(*) from biz_member_coupon where order_no=#{orderNo} and deleted=0")
    Integer selectCountByOrderNo(@Param("orderNo") String orderNo);

    @Update("update biz_member_coupon set member_id=#{memberId} where mobile=#{mobile} and isnull(member_id) and status=0 and deleted=0")
    Integer updateMemberIdByMobile(@Param("mobile") String mobile, @Param("memberId") Long memberId);

    @Select("select count(*) from biz_member_coupon where member_id=#{memberId} and status=0 and deleted=0")
    Integer selectCountByMemberId(@Param("memberId") Long memberId);

}